package bestone.qt.commond;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;

public class QuitHandler {

	/**
	 * 确认是否退出
	 */
	public static void quitConfirm(final Activity activity, final String tag) {
		Builder builder = new Builder(activity);

		builder.setTitle("确认(confirm)");
		builder.setMessage("确定退出本软件(Are you sure to exit)？");
		builder.setPositiveButton("确定(sure)", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {

				killProcess(activity);
				ActivityManager activityMgr = (ActivityManager) activity.getSystemService(activity.ACTIVITY_SERVICE);
				activityMgr.restartPackage(activity.getPackageName());
			}
		});
		builder.setNegativeButton("取消(cancle)", null);
		builder.show();
	}

	/**
	 * 彻底退出程序 杀死进程
	 */
	public static void killProcess(Activity activity) {
		try {
			activity.finish();
			android.os.Process.killProcess(android.os.Process.myPid());
		} catch (Exception e) {

		}
	}
}
